
package com.ruoyi.web.controller.mes;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.kt.mes.domain.Site;
import com.kt.mes.service.ISiteService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 工位Controller
 *
 * @author lzc
 * @date 2021-01-08
 */
@RestController
@RequestMapping("/mes/site")
public class SiteController extends BaseController
{
    @Autowired
    private ISiteService siteService;

    /**
     * 查询工位列表
     */
    @PreAuthorize("@ss.hasPermi('mes:site:list')")
    @GetMapping("/list")
    public TableDataInfo list(Site site)
    {
        startPage();
        List<Site> list = siteService.selectSiteList(site);
        return getDataTable(list);
    }

    /**
     * 导出工位列表
     */
    @PreAuthorize("@ss.hasPermi('mes:site:export')")
    @Log(title = "工位", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Site site)
    {
        List<Site> list = siteService.selectSiteList(site);
        ExcelUtil<Site> util = new ExcelUtil<Site>(Site.class);
        return util.exportExcel(list, "site");
    }

    /**
     * 获取工位详细信息
     */
    @PreAuthorize("@ss.hasPermi('mes:site:query')")
    @GetMapping(value = "/{siteId}")
    public AjaxResult getInfo(@PathVariable("siteId") String siteId)
    {
        return AjaxResult.success(siteService.selectSiteById(siteId));
    }

    /**
     * 新增工位
     */
    @PreAuthorize("@ss.hasPermi('mes:site:add')")
    @Log(title = "工位", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Site site)
    {

        if(siteService.selectSiteById(site.getSiteId())!=null){
            //编号重复
            return AjaxResult.error("工位编号重复");
        }

        return toAjax(siteService.insertSite(site));
    }

    /**
     * 修改工位
     */
    @PreAuthorize("@ss.hasPermi('mes:site:edit')")
    @Log(title = "工位", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Site site)
    {
        return toAjax(siteService.updateSite(site));
    }

    /**
     * 删除工位
     */
    @PreAuthorize("@ss.hasPermi('mes:site:remove')")
    @Log(title = "工位", businessType = BusinessType.DELETE)
    @DeleteMapping("/{siteIds}")
    public AjaxResult remove(@PathVariable String[] siteIds)
    {
        return toAjax(siteService.deleteSiteByIds(siteIds));
    }
}
